<template>
  <div>
    <div class="wrapper">
      <Anchor ref="anchor" :labelList="labels" :labelWidth="100">
        <div id="row-01">
          <FormPanel ref="formPanel1" :list="formList1" formType="add" :cols="3" labelWidth="110" :scrollContainer="scrollWrap" :isSubmitBtn="false" @formChange="formChangeHandle1" />
        </div>
        <div id="row-02">
          <FormPanel ref="formPanel4" :list="formList4" formType="add" :cols="2" labelWidth="110" :scrollContainer="scrollWrap" :isSubmitBtn="false" @formChange="formChangeHandle4" />
        </div>
        <div id="row-03">
          <FormPanel ref="formPanel5" :list="formList5" formType="add" :cols="3" labelWidth="110" :scrollContainer="scrollWrap" :isSubmitBtn="false" @formChange="formChangeHandle5" />
        </div>
        <div id="row-04">
          <BreakSpace label="处理明细"></BreakSpace>
          <FilterTable
            ref="table1"
            :columns="columns1"
            :height="'auto'"
            :isSelectColumn="false"
            :isToperInfo="false"
            :isColumnFilter="false"
            :dataSource="complaintDetailList"
            :onCellChange="onCellChange"
            columnsRef="khtsKhtsmxClxxTable"
            :onColumnsChange="columns => (this.columns = columns)"
          >
            <template slot="controls" slot-scope="props">
              <el-button v-if="type != 'detail' && !isClosed" size="small" type="primary" icon="el-icon-plus" @click="addComplaintDetail">新增</el-button>
            </template>
          </FilterTable>
        </div>
        <div id="row-05">
          <FormPanel ref="formPanel6" :list="formList6" formType="add" :cols="3" labelWidth="110" :scrollContainer="scrollWrap" :isSubmitBtn="false" @formChange="formChangeHandle6" />
        </div>
      </Anchor>
    </div>

    <div :style="{ position: 'absolute', left: 0, bottom: 0, right: 0, zIndex: 9, borderTop: '1px solid #e9e9e9', padding: '10px 20px', background: '#fff', textAlign: 'right' }">
      <AjaxButton v-if="type != 'detail'" :click="acceptance" type="primary" :loading="loginBtnState">受&nbsp;&nbsp;理</AjaxButton>
      <AjaxButton v-if="type != 'detail'" :click="commit" type="primary" :loading="loginBtnState">保&nbsp;&nbsp;存</AjaxButton>
      <AjaxButton v-if="type != 'detail'" :click="report" type="primary" :loading="loginBtnState">上&nbsp;&nbsp;报</AjaxButton>
      <el-button type="primary" @click="complaintReturnVisit()">客户回访</el-button>
      <el-button type="primary" @click="complaintExcute()">方案实施</el-button>
      <el-button v-if="type != 'detail'" type="primary" :loading="loginBtnState" @click="exhale('0')">智能外呼</el-button>
      <el-button v-if="type != 'detail'" type="primary" :loading="loginBtnState" @click="exhale('00')">加0外呼</el-button>
      <el-button :disabled="this.type == 'create' ? true : false" size="small" icon="el-icon-printer" @click="printKesudan">打印</el-button>
      <el-button type="primary" :loading="loginBtnState" @click="openComplaintHistory()">投诉历史</el-button>
      <el-button type="primary" :loading="loginBtnState" @click="openRepairHistory()">维修历史</el-button>
      <el-button type="primary" :loading="loginBtnState" @click="openReturnVisitHistory()">回访历史</el-button>
      <el-button type="primary" @click="exit">关 闭</el-button>
    </div>
    <!-- ______________________________________________ 改造______________________________________________ -->
    <!-- <div class="box">
      投诉信息
      <hr class="hr1" />
      <FormPanel ref="formPanel1" :list="formList1" formType="add" :cols="3" labelWidth="150" :scrollContainer="scrollWrap" :isSubmitBtn="false" @formChange="formChangeHandle1" />
    </div>
    <div class="box">
      投诉调查
      <hr class="hr1" />
      <FormPanel ref="formPanel4" :list="formList4" formType="add" :cols="2" labelWidth="100%" :scrollContainer="scrollWrap" :isSubmitBtn="false" @formChange="formChangeHandle4" />
    </div>
    <div class="box">
      状态登记
      <hr class="hr1" />
      <FormPanel ref="formPanel5" :list="formList5" formType="add" :cols="3" labelWidth="150" :scrollContainer="scrollWrap" :isSubmitBtn="false" @formChange="formChangeHandle5" />
    </div>
    <div v-if="type != 'create'" class="box">
      处理明细
      <el-button v-if="type != 'detail' && !isClosed" style="margin-left:20px" size="small" :scrollContainer="scrollWrap" type="primary" icon="el-icon-plus" @click="addComplaintDetail"
        >新增</el-button
      >
      <hr class="hr1" />
      <FilterTable
        ref="table1"
        :columns="columns1"
        :height="'auto'"
        :isSelectColumn="false"
        :isToperInfo="false"
        :isColumnFilter="false"
        :dataSource="complaintDetailList"
        :onCellChange="onCellChange"
        columnsRef="khtsKhtsmxClxxTable"
        :onColumnsChange="columns => (this.columns = columns)"
      ></FilterTable>
    </div>
    <div class="box">
      改进分析
      <hr class="hr1" />
      <FormPanel ref="formPanel6" :list="formList6" formType="add" :cols="3" labelWidth="100%" :scrollContainer="scrollWrap" :isSubmitBtn="false" @formChange="formChangeHandle6" />
    </div> -->
    <!-- 工单选择页面 -->
    <Drawer :visible.sync="showChooseRO" title="工单号" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <ChooseRO :vinData="vinData" @req="reqChooseRO" @cancle="closeDia" />
    </Drawer>
    <!-- 实施方案 -->
    <Drawer :visible.sync="showComplaintExcute" title="实施方案" :width="650" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <ComplaintExcute
        :excuteComplaintId="excuteComplaintId"
        :excuteComplaintNo="excuteComplaintNo"
        :excuteComplaintVin="excuteComplaintVin"
        :optTypes="optTypes"
        @reqExcute="reqExcuteInfo"
        @cancle="closeDia"
      />
    </Drawer>
    <!-- 客户回访 -->
    <Drawer :visible.sync="showComplaintReturn" title="客户回访" :width="650" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <ComplaintReturn
        :excuteComplaintId="excuteComplaintId"
        :excuteComplaintNo="excuteComplaintNo"
        :excuteComplaintVin="excuteComplaintVin"
        :optTypes="optTypes"
        @reqReturn="reqReturnInfo"
        @cancle="closeDia"
      />
    </Drawer>
    <!-- 投诉历史 -->
    <Drawer :visible.sync="showComplaintHistory" title="投诉历史" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <ComplaintHistory :vin="chooseVin" @close="closeDia" />
    </Drawer>
    <!-- 维修历史 -->
    <Drawer :visible.sync="showRepairHistory" title="维修历史" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <RepairHistory :getdata="repairHistoryData" @close="closeDia" />
    </Drawer>
    <!-- 回访历史 -->
    <Drawer :visible.sync="showReturnVisitHistory" title="回访历史" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <ReturnVisisHisitory :resData="visitHistoryData" @close="closeDia" />
    </Drawer>

    <!-- - 打印投诉单 king 20200715  <BasePrint ref="print" isPreview directPrint :data="printlist" template="complaint/complainttemplate" /> -->

    <BasePrint ref="print" :data="printlist" destroyOnClose template="customerRepair/customerComplaint/printTemplate" />
  </div>
</template>
<script>
import { mapActions, mapState } from 'vuex';
import dictCode from '@/utils/dictCode';
import * as types from '@/api/customerRepair/customerComplaint/customerComplaintReception/types.js';
import { dictionary } from '@/utils/dictMixin';
import { getUser } from '@/assets/js/auth';
import { getOwnerCode } from '@/assets/js/auth';
import { confirmAction, isFormEmpty } from '@/utils';
import ChooseRO from '../components/chooseRO';
import ChooseVehicle from '../components/chooseVehicle';
import ComplaintHistory from '@/pages/repair/business/customer/combination/complaint';
import RepairHistory from '@/pages/repair/business/customer/Repairhistory/historypop.vue';
import ReturnVisisHisitory from '@/pages/customerRepair/customerComplaint/customerComplaintMng/complaintReturnVisitHistory.vue';
import ComplaintExcute from '@/pages/customerRepair/customerComplaint/customerComplaintMng/complaintExcuteEdit.vue';
import ComplaintReturn from '@/pages/customerRepair/customerComplaint/customerComplaintMng/complaintReturnEdit.vue';
import {
  addComplaint,
  saveComplaint,
  sendAccComplaint,
  sendAccAcceptance,
  getCompalaintById,
  delComplaintDetailById,
  closeComplaintById,
  searchDealerOrg,
  getDealerUser,
  findAllRepairType,
  getModelList,
  searchRepairOrder,
  searchVehicle
} from '@/api/customerRepair/customerComplaint/customerComplaintMng';
import { saveComplaintAndDetail } from '@/api/customerRepair/customerComplaint/customerComplaintAnalysis';
import { searchRoleByCode } from '@/api/common/empSelect/index';
import { phoneAndMobel, VIN, isValidateDouble, ownerLicensePlate } from '@/utils/validate';
import moment from 'moment';

export default {
  name: 'NemoCustomerComplaintEditPage',
  components: {
    ChooseRO,
    ChooseVehicle,
    RepairHistory,
    ReturnVisisHisitory,
    ComplaintHistory,
    ComplaintExcute,
    ComplaintReturn
  },
  mixins: [dictionary],
  props: {
    editComplaintId: Number,
    type: {
      type: String,
      default: 'create'
    },
    flag: {
      type: String,
      default: '1' // 1 投诉模块，2 CTI弹屏 ，3 关怀模块
    },
    rowData: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    this.scrollWrap = null;
    this.BaseTable = null;
    this.excuteData = {};
    this.returnData = {};
    // nowDate: null;
    return {
      // king 20200716
      printlist: {},

      labels: this.createAnchorLabels(),
      // labels: [
      //   { title: '投诉信息', id: 'row-01' },
      //   { title: '投诉调查', id: 'row-02' },
      //   { title: '状态登记', id: 'row-03' },
      //   { title: '处理明细', id: 'row-04' },
      //   { title: '改进分析', id: 'row-05' }
      // ],
      listStyle: { overflow: 'hidden', 'max-height': '100px', 'text-overflow': 'ellipsis', display: '-webkit-box', '-webkit-box-orient': 'vertical' },
      bottonName: '展开全文',
      bottonNameT: '展开全文',
      // 投诉单接待人id
      receptionstId: [],
      formList1: this.createFormList1(), // 投诉信息表单
      formList4: this.createFormList4(), // 投诉调查表单
      formList5: this.createFormList5(), // 状态登记表单
      formList6: this.createFormList6(), // 状态登记表单
      firstContactTime: '', // 判断首次联系时间
      form1Over: false, // 投诉信息表单验证成功
      form2Over: false, // 工单信息表单验证成功
      form3Over: false, // 车辆信息表单验证成功
      form4Over: false, // 投诉调查表单验证成功
      form5Over: false, // 状态登记表单验证成功
      form6Over: false, // 状态登记表单验证成功
      showChooseRO: false, // 是否显示选择工单
      showChooseVehicle: false, // 是否显示选择车辆信息

      excuteComplaintId: null,
      excuteComplaintNo: null,
      excuteComplaintVin: null,
      optTypes: 'edit',

      customerComplaint: {
        complaintId: ''
      }, // 最终保存客户投诉对象
      columns1: this.createTableColumns1(), // 跟进信息表格列
      complaintDetailList: [], // 跟进信息表格数据

      closeing: false, // 判断是否可以结案
      isClosed: false, // 是否结案成功
      dealerOrgId: null,
      emplList: [],
      compliantTypeList: [
        { text: '服务类', value: 82151001 },
        { text: '技术类', value: 82151002 },
        { text: '销售类', value: 82151003 },
        { text: '金融类', value: 82151004 },
        { text: '备件类', value: 82151005 }
      ],
      compliantKindList: [
        { text: '投诉单', value: 82131001 },
        { text: '建议单', value: 82131003 },
        { text: '咨询单', value: 82131004 },
        { text: '表扬单', value: 82131005 }
      ],
      complaintMainTypeList: [],
      complaintSubTypeList: [],
      vinData: null,
      /* 呼叫中心所需字段----begin */
      afterVal: '',
      HFDH: '',
      ctiUrl: null,
      callid: null,
      /* 呼叫中心所需字段 ----end*/
      showComplaintHistory: false, // 显示投诉历史dialog
      showRepairHistory: false, // 显示维修历史dialog
      showReturnVisitHistory: false, // 显示回访历史dialog
      showComplaintExcute: false, // 處理方案
      showComplaintReturn: false, // 回訪錄入
      repairHistoryData: {}, // 维修历史传入数据
      visitHistoryData: {}, // 回访历史传入数据
      chooseVin: '', // 选中的vin
      ownerName: '', // 从工单带回来的车主姓名
      sa: '', // 从工单带回来的服务顾问
      ct: '' // 从工单带回来的责任技师
    };
  },
  computed: {
    ...mapState('app', ['btnLoading']),
    loginBtnState() {
      return this.btnLoading[types.SAVE];
    }
  },
  created() {
    console.log('rowData', this.rowData);
  },
  mounted() {
    this.scrollWrap = document.querySelector('.scroll-wrapper');
    this.getEmp();
    this.getModelList();
    this.after();
    this.formList1.find(x => x.fieldName == 'complaintType').itemList = this.compliantTypeList;
    if (this.editComplaintId) {
      this.getCompalaint();
    }
    if (this.type === 'create') {
      const nowDate = this.getNowDate();
      this.formList1.find(item => item.fieldName === 'complaintDate').initialValue = nowDate; // 投诉时间
      this.formList1.find(item => item.fieldName === 'complaintKind').itemList = this.compliantKindList; // 单据类型
    } else {
      this.formList1.find(item => item.fieldName === 'complaintKind').itemList = this.createDictList('8213'); // 单据类型
      if (this.type === 'detail') {
        this.formList1.find(item => item.fieldName === 'complaintName').rules = null;
        this.formList1.find(item => item.fieldName === 'complaintMobile').rules = null;
        this.formList1.find(item => item.fieldName === 'complaintType').rules = null;
        this.formList1.find(item => item.fieldName === 'complaintKind').rules = null;
        this.formList1.find(item => item.fieldName === 'complaintMainType').rules = null;
        this.formList1.find(item => item.fieldName === 'complaintSubType').rules = null;
        this.formList1.find(item => item.fieldName === 'handleStatus').rules = null;
        /* 查看明细页面去除必填项 */
        this.formList4.find(item => item.fieldName === 'complaintSummary').rules = [];
        this.formList4.find(item => item.fieldName === 'complaintReason').rules = null;
        // this.formList4.find(item => item.fieldName === 'surveyContent').rules = null;
        this.formList4.find(item => item.fieldName === 'resolvent').rules = null;
        this.formList4.find(item => item.fieldName === 'asdtxt').rules = null;
        /* 查看明细页面去除必填项 */
        this.formList5.find(item => item.fieldName === 'priority').rules = null;
        this.formList5.find(item => item.fieldName === 'complaintOrigin').rules = null;
        this.formList5.find(item => item.fieldName === 'result').rules = null;
      }
    }
    this.$refs.anchor.$refs.scroll.scrollTop = 0;
    this.setDefaultDic();
    // this.getDealerOrg();
    if (this.flag == '2') {
      // CTI弹屏
      this.formList1.find(item => item.fieldName === 'complaintMobile').initialValue = this.rowData.phone; // 投诉电话号
      this.formList1.find(item => item.fieldName === 'complaintMobile').initialValue = this.rowData.phone; // 投诉电话号
    } else if (this.flag === '15721001' || this.flag === '15721002' || this.flag === '15721003' || this.flag === '15721004' || this.flag === '15721005' || this.flag === '15721006') {
      this.getRoInfo(this.rowData);
    }
  },
  methods: {
    createAnchorLabels() {
      return [
        { title: '投诉信息', id: 'row-01' },
        { title: '投诉调查', id: 'row-02' },
        { title: '状态登记', id: 'row-03' },
        { title: '处理明细', id: 'row-04' },
        { title: '改进分析', id: 'row-05' }
      ];
    },
    // 投诉信息表单
    createFormList1() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '投诉信息'
        },
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'license',
          disabled: !(this.type == 'create'),
          readonly: false,
          // style: { width: '90%' },
          unitRender: props => {
            return (
              <div>
                <i slot="suffix" style="line-height: 30px" class="el-input__icon el-icon-circle-plus" onClick={() => this.openChooseRO()}></i>
                <i slot="suffix" style="line-height: 30px" class="el-input__icon el-icon-error" onClick={() => this.delRepairOrder()}></i>
              </div>
            );
          }
        },
        {
          type: 'INPUT',
          label: '底盘号',
          fieldName: 'vin',
          disabled: !(this.type == 'create'),
          readonly: false,
          // style: { width: '90%' },
          unitRender: props => {
            return (
              <div>
                <i slot="suffix" style="line-height: 30px" class="el-input__icon el-icon-circle-plus" onClick={() => this.openChooseRO()}></i>
                <i slot="suffix" style="line-height: 30px" class="el-input__icon el-icon-error" onClick={() => this.delRepairOrder()}></i>
              </div>
            );
          }
        },
        {
          type: 'INPUT',
          label: '投诉编号',
          fieldName: 'complaintId',
          hidden: true
        },
        {
          type: 'INPUT',
          label: '投诉编号',
          fieldName: 'complaintNo',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '投诉人姓名',
          fieldName: 'complaintName',
          disabled: !(this.type == 'create')
          // hidden: true
          // rules: [{ required: true, message: '请填写提交人', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '投诉人手机',
          fieldName: 'complaintMobile',
          disabled: !(this.type == 'create'),
          rules: [{ required: true, validator: this.checkPhone, trigger: 'blur', message: '请输入联系人手机' }]
        },
        {
          type: 'SELECT',
          label: '单据类型',
          fieldName: 'complaintKind',
          disabled: !(this.type == 'create'),
          itemList: [],
          initialValue: 82131001,
          change: val => {
            this.changeComplaintRules(val);
          },
          initialValue: null,
          rules: [{ required: true, message: '请选择单据类型', trigger: 'change' }]
        },
        {
          type: 'DATE_TIME',
          label: '投诉日期',
          maxDateTime: moment(),
          fieldName: 'complaintDate',
          disabled: true,
          initialValue: this.getNowDate()
        },
        {
          type: 'SELECT',
          label: '投诉处理状态',
          fieldName: 'handleStatus',
          disabled: this.type == 'create' || this.type == 'detail',
          initialValue: 80481001,
          itemList: this.createDictList('8048'),
          rules: [{ required: false, message: '请选择处理状态', trigger: 'change' }],
          change: val => {
            this.changePrincipalRequird(val);
          }
        },
        {
          type: 'INPUT',
          label: '投诉接待员',
          fieldName: 'receptionst',
          disabled: true,
          initialValue: getUser()
        },
        {
          type: 'INPUT',
          label: '委托书',
          fieldName: 'roNo',
          disabled: this.type == 'detail'
        },
        {
          type: 'SELECT',
          label: '车型',
          fieldName: 'vehicleModel',
          disabled: this.type == 'detail',
          itemList: [],
          initialValue: null,
          rules: [{ required: true, message: '请选择车型', trigger: 'change' }]
        },
        {
          type: 'DATE',
          label: '购车日期',
          disabled: this.type == 'detail',
          maxDateTime: moment(),
          fieldName: 'buyCarDate',
          rules: [{ required: false, message: '请选择购车日期', trigger: 'change' }],
          change: val => {
            this.formList1.find(x => x.fieldName === 'buyCarDate').maxDateTime = val;
          }
        },
        {
          type: 'INPUT',
          label: '送修人',
          disabled: this.type == 'detail',
          fieldName: 'deliverer'
        },
        {
          type: 'INPUT',
          label: '送修人电话',
          disabled: this.type == 'detail',
          fieldName: 'delivererMobile'
        },
        {
          type: 'SELECT',
          label: '行驶里程',
          fieldName: 'inMileage',
          disabled: this.type == 'detail',
          itemList: [
            { text: '0-2500公里', value: '1' },
            { text: '2000-5000公里', value: '2' },
            { text: '5000-7500公里', value: '3' },
            { text: '7500-10000公里', value: '4' },
            { text: '10000-20000公里', value: '5' },
            { text: '20000-30000公里', value: '6' },
            { text: '30000-40000公里', value: '7' },
            { text: '40000-50000公里', value: '8' },
            { text: '50000-60000公里', value: '9' },
            { text: '60000-70000公里', value: '10' },
            { text: '70000-80000公里', value: '11' },
            { text: '80000-90000公里', value: '12' },
            { text: '90000-100000公里', value: '13' },
            { text: '100000公里以上', value: '14' },
            { text: '未提供', value: 'null' }
          ],
          rules: [{ required: true, message: '请选择行驶里程', trigger: 'change' }]
        },
        {
          type: 'SELECT',
          label: 'JD标志',
          fieldName: 'JD',
          itemList: [
            { text: 'JD', value: 10041001 },
            { text: '非JD', value: 10041002 }
          ],
          disabled: this.type == 'detail'
        },
        {
          type: 'INPUT',
          label: '需求人',
          disabled: this.type == 'detail',
          fieldName: 'demandPerson',
          rules: [{ required: false, message: '请填写需求人', trigger: 'change' }]
        },
        {
          type: 'INPUT',
          label: '需求人手机',
          disabled: this.type == 'detail',
          fieldName: 'demandMobile',
          rules: [{ required: false, message: '请填写需求人手机', trigger: 'change' }]
        },
        {
          type: 'SELECT',
          label: '投诉类别',
          fieldName: 'complaintType',
          disabled: this.type == 'detail',
          itemList: [],
          initialValue: null,
          rules: [{ required: true, message: '请选择投诉类型', trigger: 'change' }],
          change: val => {
            this.changeComplaintMainType(val);
          }
        },
        {
          type: 'SELECT',
          label: '原因描述分类',
          fieldName: 'complaintMainType',
          disabled: this.type == 'detail',
          itemList: [],
          initialValue: null,
          rules: [{ required: true, message: '请选择原因描述分类', trigger: 'change' }],
          change: val => {
            this.changeComplaintSubType(val);
          }
        },
        {
          type: 'SELECT',
          label: '原因描述',
          fieldName: 'complaintSubType',
          disabled: this.type == 'detail',
          itemList: [],
          initialValue: null,
          rules: [{ required: true, message: '请选择原因描述', trigger: 'change' }]
        },
        {
          type: 'INPUT',
          label: '厂端下发类型',
          disabled: true,
          fieldName: 'compquestdesc'
        }
        // {
        //   type: 'DATE_TIME',
        //   label: '建单（接收）日期',
        //   maxDateTime: moment(),
        //   fieldName: 'createdAt',
        //   disabled: true,
        //   initialValue: this.getNowDate()
        // }
      ];
    },
    // 投诉调查表单
    createFormList4() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '投诉调查'
        },
        {
          // 原投诉摘要，更名为客户要求
          type: 'TEXT_AREA',
          label: '客户要求',
          fieldName: 'complaintSummary',
          disabled: this.type === 'detail',
          maxlength: 5000,
          selfCols: 2,
          rules: [{ required: true, message: '请填写客户要求', trigger: 'blur' }]
        },
        {
          // 原投诉原因，更名为客户要求
          type: 'TEXT_AREA',
          label: '反映问题',
          fieldName: 'complaintReason',
          disabled: this.type === 'detail',
          maxlength: 5000,
          selfCols: 2,
          style: { overflow: 'hidden', 'max-height': '100px', 'text-overflow': 'ellipsis', display: '-webkit-box', '-webkit-box-orient': 'vertical' }
        },
        {
          type: 'INPUT',
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.showComplaintReason()}>
                  {this.bottonName}
                </el-button>
              </div>
            );
          }
        },
        {
          type: 'TEXT_AREA',
          label: '解决方案',
          fieldName: 'resolvent',
          disabled: this.type === 'detail',
          maxlength: 5000,
          selfCols: 2,
          style: { overflow: 'hidden', 'max-height': '100px', 'text-overflow': 'ellipsis', display: '-webkit-box', '-webkit-box-orient': 'vertical' }
        },
        {
          type: 'INPUT',
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.showResolvent()}>
                  {this.bottonNameT}
                </el-button>
              </div>
            );
          }
        },
        {
          type: 'TEXT_AREA',
          label: '总部意见',
          fieldName: 'asdtxt',
          disabled: true,
          maxlength: 500,
          selfCols: 2
        }
      ];
    },
    // 状态表单
    createFormList5() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '状态登记'
        },
        {
          type: 'SELECT',
          label: '处理部门',
          fieldName: 'processDepartment',
          itemList: [
            { text: '销售', value: 'sales' },
            { text: '服务', value: 'serve' },
            { text: '市场', value: 'market' },
            { text: '其他', value: 'others' }
          ],
          // hidden: true,
          disabled: this.type == 'detail'
        },
        {
          type: 'SELECT',
          label: '负责人',
          filterable: true,
          // hidden: true,
          fieldName: 'principal',
          disabled: this.type == 'detail',
          initialValue: getUser(),
          itemList: []
        },
        {
          type: 'DATE_TIME',
          label: '首次联系时间',
          // hidden: true,
          fieldName: 'firstContactTime',
          disabled: false
        },
        {
          type: 'SELECT',
          label: '投诉级别',
          fieldName: 'priority',
          itemList: this.createDictList('8032'),
          disabled: this.type == 'detail',
          rules: [{ required: true, message: '请选择投诉级别', trigger: 'change' }],
          change: val => {
            console.log('val', val);
            if (val === 80321003 || val === 80321004) {
              this.formList5.find(x => x.fieldName === 'userDemand').rules = [{ required: true, message: '请输入客户要求', trigger: 'blur' }];
            } else {
              this.formList5.find(x => x.fieldName === 'userDemand').rules = [];
            }
            if (val == 80321002) {
              // demandPerson demandMobile
              this.formList1.find(x => x.fieldName === 'demandPerson').rules = [{ required: true, message: '请输入需求人', trigger: 'blur' }];
              this.formList1.find(x => x.fieldName === 'demandMobile').rules = [{ required: true, message: '请输入需求人手机', trigger: 'blur' }];
            }
            this.formList5 = [...this.formList5];
          }
        },
        {
          type: 'SELECT',
          label: '投诉来源',
          fieldName: 'complaintOrigin',
          itemList: this.createDictList('8009'),
          disabled: this.type == 'detail',
          rules: [{ required: true, message: '请选择投诉来源', trigger: 'change' }]
        },
        {
          type: 'INPUT',
          label: '反馈部门',
          fieldName: 'department',
          // hidden: true,
          disabled: this.type == 'detail'
        },
        {
          type: 'SELECT',
          label: '反馈部门',
          fieldName: 'department',
          disabled: this.type == 'detail',
          itemList: []
        },
        {
          type: 'SELECT',
          label: '被投诉员工',
          filterable: true,
          disabled: this.type == 'detail',
          fieldName: 'beComplaintEmp',
          itemList: []
        },
        {
          type: 'SELECT',
          label: '投诉结果',
          fieldName: 'result',
          itemList: this.createDictList('8205'),
          disabled: this.type == 'detail',
          rules: [{ required: true, message: '请选择投诉结果', trigger: 'change' }],
          change: val => {
            this.changeCloseStatus();
          }
        },
        {
          type: 'SELECT',
          label: '用户初始情绪',
          fieldName: 'attitude1',
          itemList: [
            { text: '非常满意', value: '1' },
            { text: '很满意', value: '2' },
            { text: '一般', value: '3' },
            { text: '不满意', value: '4' },
            { text: '非常不满意', value: '5' }
          ],
          disabled: this.type == 'detail',
          rules: [{ required: true, message: '请选择用户初始化情绪', trigger: 'change' }]
        },
        {
          type: 'TEXT_AREA',
          label: '备注信息',
          fieldName: 'userDemand',
          selfCols: 2,
          disabled: this.type == 'detail'
        }
      ];
    },
    // 改进表单
    createFormList6() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '改进分析'
        },
        {
          type: 'TEXT_AREA',
          label: '原因分析',
          fieldName: 'causeAnalysis',
          maxlength: 500,
          disabled: this.type == 'detail',
          selfCols: 3,
          style: { overflow: 'hidden', 'max-height': '100px', 'text-overflow': 'ellipsis', display: '-webkit-box', '-webkit-box-orient': 'vertical' }
        },
        {
          type: 'TEXT_AREA',
          label: '预防/改进措施',
          fieldName: 'improvementMeasures',
          maxlength: 500,
          disabled: this.type == 'detail',
          selfCols: 3,
          style: { overflow: 'hidden', 'max-height': '100px', 'text-overflow': 'ellipsis', display: '-webkit-box', '-webkit-box-orient': 'vertical' }
        }
      ];
    },
    // 跟进信息表格
    createTableColumns1() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          fixed: 'left',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 50,
          hidden: this.type == 'detail',
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.delComplaintDetail(props.row)}>
                  删除
                </el-button>
              </div>
            );
          }
        },
        {
          title: '处理时间',
          dataIndex: 'dealDate',
          disabled: true,
          showOverflowTooltip: true
        },
        {
          title: '处理人',
          dataIndex: 'dealer',
          editable: true,
          filterable: true,
          editType: 'select',
          editRequired: this.type == 'create',
          editItems: [],
          // initialValue:getuser(),
          disabled: this.type == 'detail'
        },
        {
          title: '处理结果描述',
          dataIndex: 'dealResult',
          editable: true,
          editType: 'input',
          editRequired: true,
          disabled: this.type == 'detail'
        },
        {
          title: '备注',
          dataIndex: 'remark',
          editable: true,
          editType: 'input',
          disabled: this.type == 'detail'
        }
      ];
    },
    // 2020.7.25      反映问题展开全文操作
    showComplaintReason() {
      if (this.bottonName === '展开全文') {
        this.formList4.find(item => item.fieldName === 'complaintReason').style = {};
        this.bottonName = '收起全文';
      } else {
        this.formList4.find(item => item.fieldName === 'complaintReason').style = this.listStyle;
        this.bottonName = '展开全文';
      }
    },
    showResolvent() {
      if (this.bottonNameT === '展开全文') {
        this.formList4.find(item => item.fieldName === 'resolvent').style = {};
        this.bottonNameT = '收起全文';
      } else {
        this.formList4.find(item => item.fieldName === 'resolvent').style = this.listStyle;
        this.bottonNameT = '展开全文';
      }
    },
    // 处理明细表格改变时
    onCellChange() {
      this.changeCloseStatus();
    },
    // 当前选中已处理时，处理人改成必填
    changePrincipalRequird(val) {
      if (val == 80481002) {
        this.formList5.find(item => item.fieldName === 'principal').rules = [{ required: true, message: '请填写处理人', trigger: 'blur' }];
      } else {
        this.formList5.find(item => item.fieldName === 'principal').rules = [];
      }
      this.formList5 = [...this.formList5];
    },
    // 内容改变时，置灰结案按钮，置亮保存按钮
    changeCloseStatus() {
      this.closeing = false;
    },
    // 新增跟进明细
    addComplaintDetail() {
      let newDetail = {
        complaintNo: this.customerComplaint.complaintNo,
        dealDate: this.getNowDate(), // 处理时间
        dealer: getUser(), // 处理人
        dealResult: '', // 处理结果
        remark: '' // 备注
      };
      this.complaintDetailList.push(newDetail);
      this.complaintDetailList = [...this.complaintDetailList];
      this.changeCloseStatus();
    },
    // 删除跟进明细
    delComplaintDetail(row) {
      this.$confirm('是否确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          // 有complaintDetailId，直接真删，再从complaintDetailList中移除
          if (row.complaintDetailId) {
            delComplaintDetailById(row.complaintDetailId).then(res => {
              if (res.resultCode == 200) {
                this.complaintDetailList.splice(row.$index, 1);
              }
            });
          } else {
            // 没有complaintDetailId，直接从complaintDetailList中移除
            this.complaintDetailList.splice(row.$index, 1);
          }
          this.complaintDetailList = [...this.complaintDetailList];
          this.changeCloseStatus();
        })
        .catch(() => {});
    },
    // 获取当前时间
    getNowDate() {
      let date = new Date();
      let Y = date.getFullYear() + '-';
      let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
      let D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate() + ' ';
      let h = date.getHours() + ':';
      let m = date.getMinutes() + ':';
      let s = date.getSeconds();
      return Y + M + D + ' ' + h + m + s;
    },

    // 打开选择工单弹框
    openChooseRO() {
      this.vinData = {
        vin: this.formList1.find(item => item.fieldName === 'vin').initialValue,
        license: this.formList1.find(item => item.fieldName === 'license').initialValue
      };
      this.showChooseRO = true;
    },
    // 选择工单
    async reqChooseRO(chooseRepairOrder) {
      /* 将车主信息默认带入到投诉人字段中 */
      this.formList1.find(item => item.fieldName === 'complaintName').initialValue = chooseRepairOrder.DELIVERER; // 投诉人
      this.formList1.find(item => item.fieldName === 'complaintMobile').initialValue = chooseRepairOrder.DELIVERER_MOBILE; // 投诉人电话
      this.formList1.find(item => item.fieldName === 'demandPerson').initialValue = chooseRepairOrder.OWNER_NAME; // 需求人
      this.formList1.find(item => item.fieldName === 'demandMobile').initialValue = chooseRepairOrder.DELIVERER_MOBILE; // 需求人电话
      this.formList1.find(item => item.fieldName === 'roNo').initialValue = chooseRepairOrder.RO_NO; // 工单号
      this.formList1.find(item => item.fieldName === 'deliverer').initialValue = chooseRepairOrder.DELIVERER; // 送修人
      this.formList1.find(item => item.fieldName === 'delivererMobile').initialValue = chooseRepairOrder.DELIVERER_MOBILE; // 送修人手机
      this.formList1.find(item => item.fieldName === 'license').initialValue = chooseRepairOrder.LICENSE; // 车牌号
      this.formList1.find(item => item.fieldName === 'license').readonly = true;
      this.formList1.find(item => item.fieldName === 'vin').initialValue = chooseRepairOrder.VIN; // VIN
      this.formList1.find(item => item.fieldName === 'vin').disabled = true;
      this.formList1.find(item => item.fieldName === 'buyCarDate').initialValue = chooseRepairOrder.SALES_DATE; // 购车日期
      this.formList1.find(item => item.fieldName === 'buyCarDate').disabled = true;
      this.formList1.find(item => item.fieldName === 'JD').initialValue = chooseRepairOrder.JD_IDENTIFICATION; // JD标志
      this.formList1.find(item => item.fieldName === 'JD').disabled = true;
      this.ownerName = chooseRepairOrder.OWNER_NAME; // 车主姓名
      this.sa = chooseRepairOrder.sa; // 服务顾问
      // 将服务顾问userId转换成姓名
      if (chooseRepairOrder.sa != null || chooseRepairOrder.sa != '') {
        let roleParm = {
          role: dictCode.SERVICE_CONSULTANT
        };
        const res = await getDealerUser(this.editComplaintId);
        if (res.resultCode === 200 && res.data != null) {
          for (let i = 0; i < res.data.length; i++) {
            if (res.data[i].userId == chooseRepairOrder.sa) {
              this.sa = res.data[i].employeeName;
              break;
            }
          }
        }
      }
      this.ct = chooseRepairOrder.ct; // 责任技师
      const mileage = chooseRepairOrder.MILEAGE;
      if (mileage <= 2500) {
        this.formList1.find(item => item.fieldName === 'inMileage').initialValue = '1';
      } else if (mileage > 2500 && mileage <= 5000) {
        this.formList1.find(item => item.fieldName === 'inMileage').initialValue = '2';
      } else if (mileage > 5000 && mileage <= 7500) {
        this.formList1.find(item => item.fieldName === 'inMileage').initialValue = '3';
      } else if (mileage > 7500 && mileage <= 10000) {
        this.formList1.find(item => item.fieldName === 'inMileage').initialValue = '4';
      } else if (mileage > 10000 && mileage <= 20000) {
        this.formList1.find(item => item.fieldName === 'inMileage').initialValue = '5';
      } else if (mileage > 20000 && mileage <= 30000) {
        this.formList1.find(item => item.fieldName === 'inMileage').initialValue = '6';
      } else if (mileage > 30000 && mileage <= 40000) {
        this.formList1.find(item => item.fieldName === 'inMileage').initialValue = '7';
      } else if (mileage > 40000 && mileage <= 50000) {
        this.formList1.find(item => item.fieldName === 'inMileage').initialValue = '8';
      } else if (mileage > 50000 && mileage <= 60000) {
        this.formList1.find(item => item.fieldName === 'inMileage').initialValue = '9';
      } else if (mileage > 60000 && mileage <= 70000) {
        this.formList1.find(item => item.fieldName === 'inMileage').initialValue = '10';
      } else if (mileage > 70000 && mileage <= 80000) {
        this.formList1.find(item => item.fieldName === 'inMileage').initialValue = '11';
      } else if (mileage > 80000 && mileage <= 90000) {
        this.formList1.find(item => item.fieldName === 'inMileage').initialValue = '12';
      } else if (mileage > 90000 && mileage <= 100000) {
        this.formList1.find(item => item.fieldName === 'inMileage').initialValue = '13';
      } else if (mileage > 100000) {
        this.formList1.find(item => item.fieldName === 'inMileage').initialValue = '14';
      } else {
        this.formList1.find(item => item.fieldName === 'inMileage').initialValue = 'null';
      }
      this.showChooseRO = false;
    },
    reqExcuteInfo(excuteData) {
      this.excuteData = excuteData;
      this.showComplaintExcute = false; // 處理方案
    },
    reqReturnInfo(returnData) {
      this.returnData = returnData;
      this.showComplaintReturn = false;
    },
    // 删除工单
    delRepairOrder() {
      this.$refs.formPanel1.RESET_FORM();
      this.delVehicle();
    },
    // 打开选择车辆弹框
    openChooseVehicle() {
      this.showChooseVehicle = true;
    },
    // // 删除车辆信息
    delVehicle() {
      this.formList1.find(item => item.fieldName === 'complaintName').initialValue = null; // 投诉人
      this.formList1.find(item => item.fieldName === 'complaintMobile').initialValue = null; // 投诉人电话
      this.formList1.find(item => item.fieldName === 'roNo').initialValue = null; // 工单号
      this.formList1.find(item => item.fieldName === 'deliverer').initialValue = null; // 送修人
      this.formList1.find(item => item.fieldName === 'delivererMobile').initialValue = null; // 送修人手机
      this.formList1.find(item => item.fieldName === 'license').initialValue = null; // 车牌号
      this.formList1.find(item => item.fieldName === 'license').readonly = false;
      this.formList1.find(item => item.fieldName === 'vin').initialValue = null; // VIN
      this.formList1.find(item => item.fieldName === 'vin').disabled = false;
      this.formList1.find(item => item.fieldName === 'complaintName').initialValue = null; // 车主
      this.formList1.find(item => item.fieldName === 'complaintName').disabled = false;
      this.formList1.find(item => item.fieldName === 'buyCarDate').initialValue = null; // 购车日期
      this.formList1.find(item => item.fieldName === 'buyCarDate').disabled = false;
      this.ownerName = ''; // 车主
      this.sa = ''; // 服务顾问
      this.ct = ''; // 责任技师
    },
    // 关闭弹框
    closeDia() {
      this.showChooseRO = false;
      this.showChooseVehicle = false;
      this.showComplaintHistory = false; // 显示投诉历史dialog
      this.showReturnVisitHistory = false; // 显示回访历史dialog
      this.showRepairHistory = false; // 显示维修历史dialog
      this.showComplaintExcute = false; // 處理方案
      this.showComplaintReturn = false; // 回訪錄入
    },
    // 点击结案
    closeComplaint() {
      this.$confirm('是否确认结案?', '提示', {
        confirmButtonText: '是',
        cancelButtonText: '否',
        type: 'warning'
      })
        .then(() => {
          closeComplaintById(this.editComplaintId).then(res => {
            if (res.resultCode == 200) {
              this.isClosed = true;
              // 整个界面置为不可编辑
              this.columns1.map(x => {
                x.disabled = true;
                if (x.title == '操作') {
                  x.hidden = true;
                }
              });
              this.columns1 = [...this.columns1];
              this.formList5.map(x => {
                x.disabled = true;
                if (x.fieldName == 'closeStatus') {
                  x.initialValue = 80421002; // 设为已结案
                }
              });
              this.formList5 = [...this.formList5];
              this.$message.success('结案成功');
              this.$emit('close', false, 'refresh');
            }
          });
        })
        .catch(() => {});
    },
    // 点击提交
    async commit() {
      console.log('提交');
      // this.$refs.formPanel1.SUBMIT_FORM();
      // this.$refs.formPanel4.SUBMIT_FORM();
      // this.$refs.formPanel5.SUBMIT_FORM();
      const [errPanel1, dataPanel1] = await this.$refs.formPanel1.GET_FORM_DATA();
      if (errPanel1) {
        return this.$message.warning('请填写必填项');
      } else {
        let complaintSubType = this.formList1.find(item => item.fieldName === 'complaintSubType').itemList;
        let name = complaintSubType.find(x => x.value === dataPanel1.complaintSubType).text;
        console.log(name);
        dataPanel1.complaintSubTypeName = name;
        this.formChangeHandle1(dataPanel1);
      }
      const [errPanel4, dataPanel4] = await this.$refs.formPanel4.GET_FORM_DATA();
      if (errPanel4) {
        return this.$message.warning('请填写必填项');
      } else {
        this.formChangeHandle4(dataPanel4);
      }
      const [errPanel5, dataPanel5] = await this.$refs.formPanel5.GET_FORM_DATA();
      if (errPanel5) {
        return this.$message.warning('请填写必填项');
      } else {
        this.formChangeHandle5(dataPanel5);
      }
      const [errPanel6, dataPanel6] = await this.$refs.formPanel6.GET_FORM_DATA();
      if (errPanel6) {
        console.log('有错');
      }
      this.formChangeHandle6(dataPanel6);

      // if (this.form1Over && this.form2Over && this.form5Over) {
      this.customerComplaint.complaintDetailList = this.complaintDetailList;
      this.save();
      // this.$emit('close');
      // }
      // this.form1Over = false;
      // this.form4Over = false;
      // this.form5Over = false;
    },
    // 添加受理按钮点击事件  2020.7.30  陈镇涛
    async acceptance() {
      if (!this.customerComplaint.complaintId) {
        this.$message.error('自建单据无法受理');
        return;
      }
      sendAccAcceptance(this.customerComplaint).then(res => {
        if (res.resultCode === 200) {
          this.$message.success('受理成功');
        }
      });
    },
    // 点击提交
    async report() {
      // this.$refs.formPanel1.SUBMIT_FORM();
      // this.$refs.formPanel4.SUBMIT_FORM();
      // this.$refs.formPanel5.SUBMIT_FORM();
      const [errPanel1, dataPanel1] = await this.$refs.formPanel1.GET_FORM_DATA();
      if (errPanel1) {
        return this.$message.warning('请填写必填项');
      } else {
        let complaintSubType = this.formList1.find(item => item.fieldName === 'complaintSubType').itemList;
        let name = complaintSubType.find(x => x.value === dataPanel1.complaintSubType).text;
        console.log(name);
        dataPanel1.complaintSubTypeName = name;
        this.formChangeHandle1(dataPanel1);
      }
      const [errPanel4, dataPanel4] = await this.$refs.formPanel4.GET_FORM_DATA();
      if (errPanel4) {
        return this.$message.warning('请填写必填项');
      } else {
        this.formChangeHandle4(dataPanel4);
      }
      const [errPanel5, dataPanel5] = await this.$refs.formPanel5.GET_FORM_DATA();
      if (errPanel5) {
        return this.$message.warning('请填写必填项');
      } else {
        this.formChangeHandle5(dataPanel5);
      }
      if (!this.customerComplaint.complaintId) {
        this.$message.error('请保存后再进行上传操作');
        return;
      }
      sendAccComplaint(this.customerComplaint).then(res => {
        if (res.resultCode === 200) {
          this.$message.success('上报成功');
        }
      });
      // this.form1Over = false;
      // this.form4Over = false;
      // this.form5Over = false;
    },

    // 保存方法
    async save() {
      this.customerComplaint.ownerName = this.ownerName; // 车主
      this.customerComplaint.sa = this.sa; // 服务顾问
      this.customerComplaint.ct = this.ct; // 责任技师
      let obj = Object.assign(this.customerComplaint, this.excuteData, this.returnData);
      await saveComplaint(obj).then(res => {
        if (res.resultCode === 200) {
          if (this.type == 'edit') {
            this.getCompalaint();
          } else if (this.type == 'close') {
            this.getCompalaint();
            this.closeing = true; // 置灰保存，点亮结案
          } else {
            this.formList1.find(item => item.fieldName === 'complaintNo').initialValue = res.data.complaintNo;
            this.customerComplaint.complaintId = res.data.complaintId;
          }
          this.$message.success('保存成功');
          this.formList5 = [...this.formList5];
          // 保存成功后投诉单号回显
          // const cNo = this.formList1.find(item => item.fieldName === 'complaintNo').initialValue;
          // if(!cNo){
          //   this.formList1.find(item => item.fieldName === 'complaintNo').initialValue = res.data.complaintNo;
          // }
        }
      });
    },

    formChangeHandle1(val) {
      if (!val.complaintNo) {
        val.complaintNo = '';
      }
      Object.assign(this.customerComplaint, val);
      this.form1Over = true;
    },
    // 表单2验证回调
    formChangeHandle4(val) {
      Object.assign(this.customerComplaint, val);
      this.form4Over = true;
    },
    // 表单5验证回调
    formChangeHandle5(val) {
      Object.assign(this.customerComplaint, val);
      this.form5Over = true;
    },
    // 表单6验证回调
    formChangeHandle6(val) {
      Object.assign(this.customerComplaint, val);
      this.form6Over = true;
    },
    // 点击取消
    // cancle() {
    //   this.$refs.formPanel1.RESET_FORM();
    //   this.$refs.formPanel4.RESET_FORM();
    //   this.$refs.formPanel5.RESET_FORM();
    //   this.formList1 = [...this.formList1];
    //   this.formList4 = [...this.formList4];
    //   this.formList5 = [...this.formList5];
    //   this.customerComplaint.complaintId = '';
    //   const nowDate = this.getNowDate();
    //   this.formList1.find(item => item.fieldName === 'complaintDate').initialValue = nowDate;
    //   this.formList1.find(item => item.fieldName === 'handleStatus').initialValue = 80481001;
    // },
    closeDetail(flag) {
      this.ComplaintExcute = false;
    },
    // 子组件时，点退出
    exit() {
      this.$emit('close');
    },
    // 获取全部员工
    async getEmp() {
      const res = await getDealerUser(this.editComplaintId);
      let empList = res.data.map(x => ({ text: x.employeeName, value: x.userId + '' }));
      this.columns1.find(item => item.dataIndex === 'dealer').editItems = empList;
      this.formList5.find(item => item.fieldName === 'beComplaintEmp').itemList = empList; // 被投诉人
      this.formList5.find(item => item.fieldName === 'principal').itemList = empList; // 处理人
    },
    async getModelList() {
      const res = await getModelList();
      let modelList = res.data.map(x => ({ text: x.ACC_MODEL_NAME, value: x.ACC_MODEL_CODE + '' }));
      this.formList1.find(item => item.fieldName === 'vehicleModel').itemList = modelList; // 车型
    },
    async getRoInfo(rowData) {
      const type = rowData.visitType;
      if (type === 15721001) {
        /* 售后回访 */
        const queryParams = { roNo: rowData.wtdh };
        const res = await searchRepairOrder(queryParams);
        if (res.resultCode === 200 && res.data.rows.length > 0) {
          const roInfo = res.data.rows[0];
          /* 将车主信息默认带入到投诉人字段中 */
          this.formList1.find(item => item.fieldName === 'complaintName').initialValue = roInfo.OWNER_NAME; // 投诉人
          this.formList1.find(item => item.fieldName === 'complaintMobile').initialValue = roInfo.MOBILE; // 投诉人手机
          this.formList1.find(item => item.fieldName === 'complaintGender').initialValue = roInfo.GENDER; // 投诉人性别
          this.showChooseRO = false;
        } else {
          this.formList1.find(item => item.fieldName === 'complaintName').initialValue = rowData.khmc; // 投诉人
          this.formList1.find(item => item.fieldName === 'complaintMobile').initialValue = rowData.khyddh; // 投诉人手机
        }
      } else if (type === 15721002) {
        /* 销售回访 */
        const queryParams = { vin: rowData.dph };
        const res = await searchVehicle(queryParams);
        if (res.resultCode === 200 && res.data.rows.length > 0) {
          const roInfo = res.data.rows[0];
          /* 将车主信息默认带入到投诉人字段中 */
          this.formList1.find(item => item.fieldName === 'complaintName').initialValue = roInfo.OWNER_NAME; // 投诉人
          this.formList1.find(item => item.fieldName === 'complaintMobile').initialValue = roInfo.MOBILE; // 投诉人手机
          this.formList1.find(item => item.fieldName === 'license').initialValue = roInfo.LICENSE; // 车牌号
          this.formList1.find(item => item.fieldName === 'license').readonly = true;
          this.formList1.find(item => item.fieldName === 'vin').initialValue = roInfo.VIN; // VIN
          this.formList1.find(item => item.fieldName === 'vin').disabled = true;
          this.formList1.find(item => item.fieldName === 'vin').rules = [];
          this.formList1.find(item => item.fieldName === 'complaintName').initialValue = roInfo.OWNER_NAME; // 车主
          this.formList1.find(item => item.fieldName === 'ownerProperTy').disabled = true;
          this.formList1.find(item => item.fieldName === 'buyCarDate').initialValue = roInfo.SALES_DATE; // 购车日期
          this.formList1.find(item => item.fieldName === 'buyCarDate').disabled = true;
          this.showChooseVehicle = false;
        } else {
          this.formList1.find(item => item.fieldName === 'complaintName').initialValue = rowData.khmc; // 投诉人
          this.formList1.find(item => item.fieldName === 'complaintMobile').initialValue = rowData.khyddh; // 投诉人手机
        }
      } else {
        /* 其他回访 */
        this.formList1.find(item => item.fieldName === 'complaintName').initialValue = rowData.khmc; // 投诉人
        this.formList1.find(item => item.fieldName === 'complaintMobile').initialValue = rowData.khyddh; // 投诉人手机
      }
    },
    async getDealerOrg() {
      const res = await searchDealerOrg();
      this.formList5.find(item => item.fieldName === 'department').itemList = res.data.map(x => ({ text: x.orgName, value: x.orgId }));
    },
    // 如果有id获取客户投诉详情
    async getCompalaint() {
      const res = await getCompalaintById(this.editComplaintId);
      const cat = await getDealerUser(this.editComplaintId);
      console.log('res', res, 'res');
      this.firstContactTime = res.data.firstContactTime;
      this.formList5.find(x => x.fieldName == 'firstContactTime').disabled = this.type == 'detail' ? true : !isFormEmpty(this.firstContactTime);
      console.log(this.firstContactTime, 'firstContactTime');
      if (res.resultCode != 200) {
        this.$message.error('查询客户投诉详情失败');
        return;
      }
      if (this.type === 'detail') {
        this.formList1.find(x => x.fieldName == 'handleStatus').disabled = true;
      }
      this.customerComplaint = res.data;
      this.complaintDetailList = res.data.complaintDetailList;
      this.receptionstId = cat.data;
      this.formList6.forEach(x => {
        x.initialValue = this.customerComplaint[x.fieldName];
      });
      this.formList1.forEach(x => {
        if (x.fieldName != 'receptionst') {
          x.initialValue = this.customerComplaint[x.fieldName];
        } else {
          let id = this.customerComplaint[x.fieldName];
          for (let i = 0; i < this.receptionstId.length; i++) {
            if (this.receptionstId[i].userId == id) {
              x.initialValue = this.receptionstId[i].employeeName;
            }
          }
        }

        if (this.customerComplaint.isOem == 10041001) {
          if (x.fieldName == 'complaintType') {
            this.formList1.find(item => item.fieldName === 'complaintType').disabled = true;
          } else if (x.fieldName == 'complaintMainType') {
            this.formList1.find(item => item.fieldName === 'complaintMainType').disabled = true;
          } else if (x.fieldName == 'complaintSubType') {
            this.formList1.find(item => item.fieldName === 'complaintSubType').disabled = true;
          }
        }
      });
      this.formList1 = [...this.formList1];
      this.formList4.forEach(x => {
        x.initialValue = this.customerComplaint[x.fieldName];
      });
      this.formList4 = [...this.formList4];
      this.formList5.forEach(x => {
        x.initialValue = this.customerComplaint[x.fieldName];
        if (x.fieldName == 'principal') {
          x.rules = [{ required: true, message: '请填写处理人', trigger: 'blur' }];
        }
        if (x.fieldName === 'priority') {
          if (x.initialValue === 80321003 || x.initialValue === 80321004) {
            this.formList5.find(x => x.fieldName === 'userDemand').rules = [{ required: true, message: '请输入备注信息', trigger: 'blur' }];
          } else {
            this.formList5.find(x => x.fieldName === 'userDemand').rules = [];
          }
        }
      });
      this.formList5 = [...this.formList5];

      const defaultUser = this.formList5.find(item => item.fieldName === 'principal').initialValue;
      if (!defaultUser) {
        this.formList5.find(item => item.fieldName === 'principal').initialValue = getUser();
      }
      this.complaintDetailList = [...this.complaintDetailList];
      if (this.formList1.find(item => item.fieldName === 'complaintKind').initialValue !== 82131001) {
        /* 查看明细页面去除必填项 */
        console.log('1');
        this.formList4.find(item => item.fieldName === 'complaintSummary').rules = null;
        this.formList4.find(item => item.fieldName === 'complaintReason').rules = null;
        this.formList4.find(item => item.fieldName === 'surveyContent').rules = null;
        this.formList4.find(item => item.fieldName === 'resolvent').rules = null;
        this.formList4.find(item => item.fieldName === 'asdtxt').rules = null;
        /* 查看明细页面去除必填项 */
        this.formList5.find(item => item.fieldName === 'priority').rules = null;
        this.formList5.find(item => item.fieldName === 'complaintOrigin').rules = null;
        this.formList5.find(item => item.fieldName === 'result').rules = null;
      }
    },
    // 校验手机
    checkPhone(rule, value, callback) {
      if (!value) {
        return callback(new Error(rule.message));
      } else {
        const reg = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/;
        if (reg.test(value)) {
          callback();
        } else {
          return callback(new Error(rule.message));
        }
      }
      callback();
    },
    setDefaultDic() {
      window.console.log(this.type);
      if (this.type === 'create') {
        this.formList1.find(x => x.fieldName == 'handleStatus').initialValue = 80481001;
        this.formList1.find(x => x.fieldName == 'complaintKind').initialValue = 82131001;
      }
      if (this.type !== 'create') {
        this.formList1.find(x => x.fieldName == 'complaintMainType').itemList = this.createDictList('8216');
        this.formList1.find(x => x.fieldName == 'complaintSubType').itemList = this.createDictList('8217');
      }
    },
    changeComplaintRules(val) {
      if (val !== 82131001) {
        this.formList5.find(item => item.fieldName === 'priority').rules = null;
        this.formList5.find(item => item.fieldName === 'complaintOrigin').rules = null;
        this.formList5.find(item => item.fieldName === 'result').rules = null;
      } else {
        this.formList5.find(item => item.fieldName === 'priority').rules = [{ required: true, message: '请选择投诉级别', trigger: 'change' }];
        this.formList5.find(item => item.fieldName === 'complaintOrigin').rules = [{ required: true, message: '投诉来源', trigger: 'change' }];
        this.formList5.find(item => item.fieldName === 'result').rules = [{ required: true, message: '投诉结果', trigger: 'change' }];
      }
    },
    changeComplaintMainType(val) {
      this.formList1.find(x => x.fieldName == 'complaintMainType').initialValue = '';
      this.formList1.find(x => x.fieldName == 'complaintMainType').itemList = [];
      this.formList1.find(x => x.fieldName == 'complaintSubType').initialValue = '';
      this.formList1.find(x => x.fieldName == 'complaintSubType').itemList = [];
      if (val === 82151001) {
        /* 服务 */
        this.complaintMainTypeList = [{ text: '服务类', value: 82161001 }];
        this.formList1.find(x => x.fieldName == 'complaintMainType').itemList = this.complaintMainTypeList;
      } else if (val === 82151002) {
        /* 技术 */
        this.complaintMainTypeList = [{ text: '技术类', value: 82161002 }];
        this.formList1.find(x => x.fieldName == 'complaintMainType').itemList = this.complaintMainTypeList;
      } else if (val === 82151003) {
        /* 销售 */
        console.log('11111');
        this.complaintMainTypeList = [{ text: '销售类', value: 82161003 }];
        this.formList1.find(x => x.fieldName == 'complaintMainType').itemList = this.complaintMainTypeList;
      } else if (val === 82151004) {
        /* 一汽-大众金融服务政策 */
        this.complaintMainTypeList = [{ text: '金融类', value: 82161004 }];
        this.formList1.find(x => x.fieldName == 'complaintMainType').itemList = this.complaintMainTypeList;
      } else if (val === 82151005) {
        /* 备件类 */
        this.complaintMainTypeList = [{ text: '备件类', value: 82161005 }];
        this.formList1.find(x => x.fieldName == 'complaintMainType').itemList = this.complaintMainTypeList;
      }
    },
    changeComplaintSubType(val) {
      this.formList1.find(x => x.fieldName == 'complaintSubType').initialValue = '';
      this.formList1.find(x => x.fieldName == 'complaintSubType').itemList = [];
      if (val === 82161001) {
        /* 服务类 */
        this.complaintSubTypeList = [
          { text: 'T投诉-经销商-服务水平', value: 82171001 },
          { text: 'T投诉-经销商-服务规范', value: 82171002 },
          { text: 'T投诉-经销商-工时费用', value: 82171003 },
          { text: 'T投诉-经销商-服务替换车', value: 82171004 },
          { text: 'T投诉-经销商-紧急救援', value: 82171005 },
          { text: 'T投诉-经销商-机动性保障', value: 82171006 },
          { text: 'T投诉-经销商-备件周期', value: 82171007 },
          { text: 'T投诉-经销商-备件质量', value: 82171008 },
          { text: 'T投诉-经销商-备件价格', value: 82171009 },
          { text: 'T投诉-经销商-精品附件', value: 82171010 },
          { text: 'T投诉-车辆-随车文件(说明书/手册）', value: 82171011 },
          { text: 'T投诉-一汽-大众服务活动', value: 82171012 },
          { text: 'T投诉-一汽-大众其他', value: 82171013 },
          { text: 'T投诉-奥迪股份公司AUDI', value: 82171014 },
          { text: '紧急救援', value: 82171015 },
          { text: '服务替换车', value: 82171016 },
          { text: '服务费用', value: 82171017 },
          { text: '服务用户对待', value: 82171018 },
          { text: '服务流程', value: 82171019 },
          { text: '服务优惠活动', value: 82171020 },
          { text: '精品附件', value: 82171021 },
          { text: '二手车问题', value: 82171022 }
        ];
      } else if (val === 82161002) {
        /* 技术类 */
        this.complaintSubTypeList = [
          { text: 'T投诉-经销商-车间维修工作', value: 82171023 },
          { text: 'T投诉-车辆-非重大安全类产品质量故障', value: 82171024 },
          { text: 'T投诉-经销商-索赔', value: 82171025 },
          { text: 'T投诉-经销商-优惠索赔', value: 82171026 },
          { text: 'T投诉-车辆-RC/气襄/安全带/事故车', value: 82171027 },
          { text: '车间维修工作', value: 82171028 },
          { text: '非重大产品质量问题', value: 82171029 },
          { text: '重大产品质量问题', value: 82171030 }
        ];
      } else if (val === 82161003) {
        /* 销售类 */
        this.complaintSubTypeList = [
          { text: 'T投诉-经销商-销售业务规范', value: 82171031 },
          { text: 'T投诉-经销商-销售订车周期', value: 82171032 },
          { text: 'T投诉-经销商-车辆订购/交付', value: 82171033 },
          { text: 'T投诉-经销商-销售费用', value: 82171034 },
          { text: 'T投诉-经销商-销售用户对待', value: 82171035 },
          { text: 'T投诉-经销商-销售随车文件', value: 82171036 },
          { text: 'T投诉-一汽-大众二手车及大用户销售', value: 82171037 },
          { text: 'T投诉-一汽-大众金融服务政策', value: 82171038 },
          { text: '销售用户对待', value: 82171039 },
          { text: '销售流程', value: 82171040 },
          { text: '销售费用', value: 82171041 },
          { text: '销售优惠活动', value: 82171042 },
          { text: '直销车大用户问题', value: 82171043 }
        ];
      } else if (val === 82161004) {
        /* 金融类 */
        this.complaintSubTypeList = [{ text: '一汽-大众金融服务政策', value: 82171044 }];
      } else if (val === 82161005) {
        /* 备件类 */
        this.complaintSubTypeList = [
          { text: '备件周期', value: 82171045 },
          { text: '备件质量', value: 82171046 },
          { text: '备件价格', value: 82171047 }
        ];
      }
      this.formList1.find(x => x.fieldName == 'complaintSubType').itemList = this.complaintSubTypeList;
    },
    // 呼出系统
    exhale(a) {
      let phone = a + this.formList1.find(item => item.fieldName === 'complaintMobile').initialValue; // 投诉电话
      let complaintName = a + this.formList1.find(item => item.fieldName === 'complaintName').initialValue; // 投诉电话
      let complaintNo = this.formList1.find(item => item.fieldName === 'complaintNo').initialValue; // 投诉编号
      let ownerCode = '111';
      let userData = {
        userData: {
          COMPLAINT_NO: complaintNo,
          OWNER_CODE: ownerCode,
          OWNER_NAME: complaintName,
          date: moment().format('YYYY-MM-DD hh:MM:SS')
        }
      };
      if (CallCenter.isLogin()) {
        CallCenter.callout(phone, null, null, null, null, userData);
      } else {
        this.$notify.warning({ title: '提示信息', message: '没有外呼权限!' });
      }
    },
    complaintExcute() {
      if (this.customerComplaint.complaintId) {
        this.excuteComplaintId = this.customerComplaint.complaintId;
      } else {
        this.excuteComplaintId = null;
      }
      this.excuteComplaintNo = this.formList1.find(item => item.fieldName === 'complaintNo').initialValue;
      this.excuteComplaintVin = this.formList1.find(item => item.fieldName === 'vin').initialValue;
      if (this.type === 'detail') {
        this.optTypes = 'detail';
      } else {
        this.optTypes = 'edit';
      }
      this.showComplaintExcute = true;
    },
    complaintReturnVisit() {
      if (this.customerComplaint.complaintId) {
        this.excuteComplaintId = this.customerComplaint.complaintId;
      } else {
        this.excuteComplaintId = null;
      }
      this.excuteComplaintNo = this.formList1.find(item => item.fieldName === 'complaintNo').initialValue;
      this.excuteComplaintVin = this.formList1.find(item => item.fieldName === 'vin').initialValue;
      if (this.type === 'detail') {
        this.optTypes = 'detail';
      } else {
        this.optTypes = 'edit';
      }
      this.showComplaintReturn = true;
    },
    openComplaintHistory() {
      if (this.formList1.find(item => item.fieldName === 'vin').initialValue) {
        this.chooseVin = this.formList1.find(item => item.fieldName === 'vin').initialValue;
        this.showComplaintHistory = true;
      } else {
        this.$notify.warning({ title: '提示信息', message: '该单据无底盘号，无法查看历史投诉信息!' });
      }
    },
    /* 打印客诉单 begin king 20200715 */
    // 点击打印工单
    /* 打印客诉单 begin king 20200715 */
    // 点击打印工单
    async printKesudan() {
      const res = await getCompalaintById(this.editComplaintId);
      if (res.resultCode != 200) {
        this.$message.error('打印客户投诉详情失败');
        return;
      } else {
        // 翻译字典
        // 查询车型

        let vehicleModel = res.data.vehicleModel;
        const modelres = await getModelList();
        let printmodelList = [];
        this.printmodelList = modelres.data.map(x => ({ text: x.ACC_MODEL_NAME, value: x.ACC_MODEL_CODE + '' }));

        if (this.printmodelList.find(item => item.value === res.data.vehicleModel)) {
          res.data.vehicleModel = this.printmodelList.find(item => item.value === res.data.vehicleModel).text;
        } else {
          res.data.vehicleModel = '';
        }

        // 投诉类别

        if (this.compliantTypeList.find(item => item.value === res.data.complaintType)) {
          res.data.complaintType = this.compliantTypeList.find(item => item.value === res.data.complaintType).text;
        } else {
          res.data.complaintType = '';
        }

        // 原因描述
        if (this.createDictList('8217').find(item => item.value === res.data.complaintSubType)) {
          res.data.complaintSubType = this.createDictList('8217').find(item => item.value === res.data.complaintSubType).text;
        } else {
          res.data.complaintSubType = '';
        }

        // 投诉来源
        if (this.createDictList('8009').find(item => item.value === res.data.complaintOrigin)) {
          res.data.complaintOrigin = this.createDictList('8009').find(item => item.value === res.data.complaintOrigin).text;
        } else {
          res.data.complaintOrigin = '';
        }

        // 投诉级别
        if (this.createDictList('8032').find(item => item.value === res.data.priority)) {
          res.data.priority = this.createDictList('8032').find(item => item.value === res.data.priority).text;
        } else {
          res.data.priority = '';
        }
        // 投诉结果
        if (this.createDictList('8205').find(item => item.value === res.data.result)) {
          res.data.result = this.createDictList('8205').find(item => item.value === res.data.result).text;
        } else {
          res.data.result = '';
        }

        // 用户初始情绪
        let attitude1List = [
          { text: '非常满意', value: '1' },
          { text: '很满意', value: '2' },
          { text: '一般', value: '3' },
          { text: '不满意', value: '4' },
          { text: '非常不满意', value: '5' }
        ];

        if (attitude1List.find(item => item.value === res.data.attitude1)) {
          res.data.attitude1 = attitude1List.find(item => item.value === res.data.attitude1).text;
        } else {
          res.data.result = '';
        }
        if (attitude1List.find(item => item.value === res.data.attitude2)) {
          res.data.attitude2 = attitude1List.find(item => item.value === res.data.attitude2).text;
        } else {
          res.data.attitude2 = '';
        }
        // 部门列表
        let processDepartmentList = [
          { text: '销售', value: 'sales' },
          { text: '服务', value: 'serve' },
          { text: '市场', value: 'market' },
          { text: '其他', value: 'others' }
        ];

        if (processDepartmentList.find(item => item.value === res.data.processDepartment)) {
          res.data.processDepartment = processDepartmentList.find(item => item.value === res.data.processDepartment).text;
        } else {
          res.data.processDepartment = '';
        }
        if (processDepartmentList.find(item => item.value === res.data.department)) {
          res.data.department = processDepartmentList.find(item => item.value === res.data.department).text;
        } else {
          res.data.department = '';
        }
        console.info(res.data.firstContactTime);
        // 时间转换
        if (null != res.data.firstContactTime && '' != res.data.firstContactTime) {
          console.info('zh');

          res.data.firstContactTime = new Date(+new Date(res.data.firstContactTime) + 8 * 3600 * 1000)
            .toISOString()
            .replace(/T/g, ' ')
            .replace(/\.[\d]{3}Z/, '');
        }
        console.info(res.data.firstContactTime);
        this.printlist = res.data;
        console.info(this.printlist);
        this.$nextTick(() => {
          this.$refs.print.EXCUTE_PRINT();
        });
      }
    },
    /* 打印客诉单 end king 20200715 */

    openReturnVisitHistory() {
      if (this.formList1.find(item => item.fieldName === 'complaintName').initialValue) {
        const khmc = this.formList1.find(item => item.fieldName === 'complaintName').initialValue;
        const pzh = this.formList1.find(item => item.fieldName === 'license').initialValue;
        this.visitHistoryData = {
          ownerNo: '',
          pzh: pzh,
          khmc: khmc
        };
        this.showReturnVisitHistory = true;
      } else {
        this.$notify.warning({ title: '提示信息', message: '投诉人姓名为空，无法查看历史回访信息!' });
      }
    },
    openRepairHistory() {
      if (this.formList1.find(item => item.fieldName === 'vin').initialValue) {
        this.title_history = '维修历史';
        const vin = this.formList1.find(item => item.fieldName === 'vin').initialValue;
        const license = this.formList1.find(item => item.fieldName === 'license').initialValue;
        const complaintName = this.formList1.find(item => item.fieldName === 'complaintName').initialValue;
        this.repairHistoryData = {
          LICENSE: license,
          VIN: vin,
          ENGINE_NO: null,
          OWNER_NAME: complaintName
        };
        this.showRepairHistory = true;
      } else {
        this.$notify.warning({ title: '提示信息', message: '该单据无底盘号，无法查看历史维修信息!' });
      }
    },
    after() {
      let that = this;
      CallCenter.addEventListener('after', function(json) {
        console.log('验证是否监听到了after方法=============================>true');
        console.log('返回值================================>begin');
        console.log('返回值录音第一段================================>', json.recordDownloadUrl);
        console.log('返回值录音第二段================================>', json.mediano);
        console.log('返回值录音第三段================================>', json.filename);
        let url = json.recordDownloadUrl + '/' + json.mediano + '?file=' + json.filename;
        console.log('返回值录音路径================================>', url);
        let getCallId = json.callid;
        console.log('返回值CALLID================================>', getCallId);
        that.ctiUrl = url;
        console.log('返回URL值录音后台传递================================>', that.ctiUrl);
        that.callid = getCallId;
        console.log('返回CALLID值录音后台传递================================>', that.callid);
      });
    }
  }
};
</script>
<style lang="less" scoped>
.wrapper {
  height: calc(100vh - 135px);
}
.box {
  border: 1px solid @borderColor;
  border-radius: @borderRadius;
  box-shadow: @boxShadow;
  padding: @modulePadding;
  margin-top: 20px;
}
.hr1 {
  border: 0;
  height: 1px;
  background-color: @borderColor;
}
</style>
